import request from "@/utils/request";
import { MenuForm, MenuQuery, MenuVO } from "./type";

const api: string = "/menus";

/**
 * 获取路由列表
 */
export function listRouteApi(): Result<any> {
  return request({
    url: "/user/getUserMenus",
    method: "post",
  });
}

/**
 * 获取菜单树形列表
 *
 * @param queryParams
 */
export function treeMenuApi(queryParams: MenuQuery): Result<MenuVO[]> {
  return request({
    url: `${api}/treeMenus`,
    method: "get",
    params: queryParams,
  });
}

/**
 * 获取菜单下拉树形列表
 */
export function getMenuOptionsApi(): Result<OptionType[]> {
  return request({
    url: `${api}/getMenuOptions`,
    method: "get",
  });
}

/**
 * 获取菜单表单数据
 *
 * @param id
 */
export function getMenuFormApi(id: number): Result<MenuForm> {
  return request({
    url: `${api}/` + id + "/form",
    method: "get",
  });
}

/**
 * 添加菜单
 *
 * @param data
 */
export function addMenuApi(data: MenuForm): Result<void> {
  return request({
    url: `${api}/addMenu`,
    method: "post",
    data: data,
  });
}

/**
 * 修改菜单
 *
 * @param data
 */
export function updateMenuApi(data: MenuForm): Result<void> {
  return request({
    url: `${api}/editMenu`,
    method: "post",
    data: data,
  });
}

/**
 * 删除菜单
 *
 * @param id 菜单ID
 */
export function deleteMenuApi(id: number): Result<void> {
  return request({
    url: `${api}/deleteMenu/` + id,
    method: "delete",
  });
}
